// pages/user_end/commission/index/index.js
const url = require('../../../../utils/url')
const request = require('../../../../utils/request')
const utils = require('../../../../utils/util')
Page({

  /**
   * 页面的初始数据
   * member_commission_total 服务订单收益
      member_commission_count 服务订单数量
      service_commission_total 包年月订单收益
      service_commission_count 包年月订单数量
      commission_total 总收益
   */
  data: {
    member_commission_total: 0,
    member_commission_count: 0,
    service_commission_total: 0,
    service_commission_count: 0,
    commission_total: 0,
    can_withdrawal_total: 0,
    userinfo:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

    utils.getUserInfo().then(res => {
      this.setData({
        token: res.token,
        islogin: 1,
        userinfo: res
      })

      setTimeout(() => {
        this.getCensus()
      }, 150)
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
 
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
  },
  getCensus: function () {
    console.log('token', this.data.token)
    request.request(url.getcensus, {
      token: this.data.token
    }, url.REQUEST_METHOD_GET).then(res => {
      // if(res.data.code == 0) {
      //   wx.navigateBack();
      //   return;
      // }
      console.log('getcensus', res)
      this.setData({
        member_commission_total: res.data.data.member_commission_total,
        member_commission_count: res.data.data.member_commission_count,
        service_commission_total: res.data.data.service_commission_total,
        service_commission_count: res.data.data.service_commission_count,
        commission_total: res.data.data.commission_total,
        can_withdrawal_total: res.data.data.can_withdrawal_total,
      })
    })
  },
  goTeam: function () {
    wx.navigateTo({
      url: '../team/index',
    })
  },

  goOrderF: function () {
    wx.navigateTo({
      url: '../order_log/index',
    })
  },
  goVipF: function () {
    wx.navigateTo({
      url: '../vip_log/index',
    })
  },
  goWithdrawal: function () {
    wx.navigateTo({
      url: '../withdrawal/withdrawal'
    })
  },
})